<?php 
class DomFileLoggerTestCase extends UnitTestCase {
	
	public function testConstruct() {
		try {
			$logger = new DomFileLogger('AZaz09-_().\'');
			$this->assertTrue(true);
		} catch( RuntimeException $e ) {
			$this->assertFalse(true, 'Exception thrown!');
		}	
		
		try {
			$logger = new DomFileLogger('""');
			$this->assertFalse(true, 'Exception not thrown!');
		} catch( RuntimeException $e ) {
			$this->assertTrue(true);
		}	
		
		try {
			$logger = new DomFileLogger('');
			$this->assertFalse(true, 'Exception not thrown!');
		} catch( RuntimeException $e ) {
			$this->assertTrue(true);
		}	
	}
	
	public function testLog() {
		$logger = new DomFileLogger('testLog');
		
		$this->assertFalse( file_exists($logger->getFilePath()) );

		$logger->log('myTest');
		
		$s = substr(file_get_contents( $logger->getFilePath()), -8, 6);
		$this->assertEqual( $s, 'myTest' );
		
		$backUp = $logger->flush();
		
		$this->assertFalse( file_exists($logger->getFilePath()) );
		
		$s = substr(file_get_contents( $backUp), -8, 6);
		$this->assertEqual( $s, 'myTest' );
		
		unlink($backUp);
		
	}
}
?>